package org.room402.entity.chat;

import cn.hutool.json.JSONObject;
import lombok.Builder;
import lombok.Data;
import org.springframework.web.reactive.socket.WebSocketSession;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
@Builder
public class UserSession {
    private String id;
    private String name;

    /**
     * 用户注册、上线时间
     */
    private LocalDateTime registerTime;

    /**
     * 头像地址
     */
    private String avatarUrl;

    private WebSocketSession session;

    /**
     * 用户创建的聊天池ID
     */
    private List<String> createdPoolIds;


    public static UserSession form(WebSocketSession session, JSONObject object, String id) {
        return UserSession.builder()
                .session(session)
                .id(id)
                .name(object.getStr("name"))
                .avatarUrl(object.getStr("avatarUrl"))
                .registerTime(LocalDateTime.now())
                .createdPoolIds(new ArrayList<>())
                .build();
    }

}
